package cn.edu.ujs.coor.repository.role;

import cn.edu.ujs.coor.model.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleRepository extends JpaRepository<Role, String>, JpaSpecificationExecutor<Role> {

    /**
     * 查询用户数据级别
     * @param userId
     * @return
     */
    @Query(value = "select max(role.data_level) from coor_role_user ru left join coor_role role on ru.role_id = role.id where user_id = ?1", nativeQuery = true)
    String findMaxLevelByUser (String userId);

    @Query(value = "select concat(node.id) from coor_access access left join coor_node node on access.node_id = node.id where access.role_id = ?1", nativeQuery = true)
    List<String> findNodeByRoleId (String roleId);
}